import { fileURLToPath, URL } from "node:url";

import { defineConfig, loadEnv, type UserConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";

// https://vitejs.dev/config/
export default defineConfig(({ command, mode, ssrBuild }) => {
    console.log("vite.config.ts", command, mode);
    const env = loadEnv(mode, process.cwd(), "");

    return {
        base: env.VITE_BASE_URL,
        plugins: [vue(), vueJsx()],
        resolve: {
            alias: {
                "@": fileURLToPath(new URL("./src", import.meta.url)),
            },
        },
        server: {
            open: true,
            proxy: {
                "/api": {
                    target: env.PROXY_DOMAIN,
                    changeOrigin: true,
                },
            },
        },
        build: {
            sourcemap: mode !== "production",
        },
    } as UserConfig;
});
